﻿using System.Activities.Expressions;
using DevExpress.Utils;
using DevExpress.Web.ASPxGridView;
using RR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    protected RegistRar regrar = new RegistRar();

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void menu_exp_ItemClick(object source, DevExpress.Web.ASPxMenu.MenuItemEventArgs e)
    {
        if (e.Item.Name == "btn_Excel")
            grd_export.WriteXlsxToResponse();
    }
    protected void grd_worker_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        if (e.NewValues["CODE"] == null)
            e.NewValues["CODE"] = regrar.Gen_id("WORKER_gen");
        var cheef = (from k in regrar.KONTRAGENT
            where k.CHIEFFIRM == 1
            select k).First();
        if (cheef != null)
        {
            if (cheef.CODE != Convert.ToInt32(e.NewValues["KONTRAGENT"]))
                e.NewValues["WORKERSTATE"] = 2;
        }
    }
    protected void grd_worker_CellEditorInitialize(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewEditorEventArgs e)
    {
        if (e.Column.FieldName == "PSW")
        {
            if (Profile.UserInfo.ActiveRole != 1)
            {
                e.Column.EditFormSettings.Visible = DefaultBoolean.False;
                e.Column.EditFormSettings.CaptionLocation = ASPxColumnCaptionLocation.None;
                e.Editor.Visible = false;
            }
            //e.Column.EditFormSettings.Visible = DefaultBoolean.False;
        }
    }
    protected void grd_worker_DataBound(object sender, EventArgs e)
    {
        if (Profile.UserInfo.ActiveRole != 1)
        {
            ASPxGridView gridView = (sender as ASPxGridView);
            GridViewDataColumn column = (gridView.Columns["PSW"] as GridViewDataColumn); 
            column.EditFormSettings.CaptionLocation = ASPxColumnCaptionLocation.None;
        }
    }
    protected void grd_worker_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {
        var cheef = (from k in regrar.KONTRAGENT
                     where k.CHIEFFIRM == 1
                     select k).First();
        if (cheef != null)
        {
            if (cheef.CODE != Convert.ToInt32(e.NewValues["KONTRAGENT"]))
                e.NewValues["WORKERSTATE"] = 2;
            
        }
    }
}